package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);
    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{checkoutTime} where id = #{id}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime checkoutTime, Long id);

    /**
     * 分页查询，查询出该userid下的所有订单
     * @param ordersPageQueryDTO
     * @return
     */

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单ID查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getById(long id);

    /***
     * 查询各个订单状态的数量
     * @param status
     * @return
     */
    @Select("select count(*) from orders where status = #{status} ")
    Integer countStatus( Integer status);

    @Select("select * from orders where status = #{status} and order_time < #{endTime}")
    List<Orders> getOrdersByStatuusAndTime(Integer status,LocalDateTime endTime);

    /**
     * 计算每天的营业额
     * @param map
     * @return
     */
    Double selectTurnoverByDay(HashMap<Object, Object> map);

    /**
     * 查询出此区间所有订单
     * @param begin
     * @param end
     * @return
     */
    int selectCount(LocalDateTime begin, LocalDateTime end,Integer status);

    /**
     * 查询出销量前十的菜品或套餐
     * @param begin
     * @param end
     * @return
     */
    List<GoodsSalesDTO> getTop10(LocalDateTime begin, LocalDateTime end);
}
